var url = location.search; //获取url中"?"符后的字串 ('?modFlag=business&role=1')
 var theRequest = new Object();
 var New ='';
 if (url.indexOf('?') != -1) {
	 var str = url.substr(1); //substr()方法返回从参数值开始到结束的字符串；
	 var strs = str.split('&');
		 for (var i = 0; i < strs.length; i++) {
		    theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]
		 }
		 New=theRequest.New; //此时的theRequest就是我们需要的参数；
 }



$(document).ready(function(){
	$.ajax({
		url:"../bannerController/banner",
		success:function(data){
			if(data !=  null){
				$('.lb-content').html("");
				$('.lb-sign').html("");
			}
			$.each(data,function(idex,item){
				if(idex == 0){
					$('.lb-content').append("<div class='lb-item active'><a href='../html/GG.html?id="+item.id+"'><img src='"+item.banner+"'></a></div>");
					$('.lb-sign').append("<li class='active'>"+(idex+1)+"</li>");
				}else{
					$('.lb-content').append("<div class='lb-item'><a href='../html/GG.html?id="+item.id+"'><img src='"+item.banner+"'></a></div>");
					$('.lb-sign').append("<li>"+(idex+1)+"</li>");
				}
				/*if(idex == 0){
					$('.lb-content').append("<li style='display:block'><a href='../html/GG.html?id="+item.id+"'><img src='"+item.banner+"'></a></li>");
				}else{
					$('#pic').append("<li style='display:none'><a href='../html/GG.html?id="+item.id+"'><img src='"+item.banner+"'></a></li>");
				}*/
			})


			// 轮播选项
			const options = {
				id: 'lb-1',              // 轮播盒ID
				speed: 600,              // 轮播速度(ms)
				delay: 5000,             // 轮播延迟(ms)
				direction: 'left',       // 图片滑动方向
				moniterKeyEvent: true,   // 是否监听键盘事件
				moniterTouchEvent: true  // 是否监听屏幕滑动事件
			}
			const lb = new Lb(options);
			lb.start();

			// 首页轮播图
			/*imgLength=$(".c-banner .banner ul li").length;
			time =setInterval(intervalImg,5000);
			
			$(".c-banner .jumpBtn ul li").each(function(){
				//为每个按钮定义点击事件
//				$(document).on('click',this,function(){
				$(this).click(function(){
					clearInterval(time);
					$(".c-banner .jumpBtn ul li").css("background-color","white");
					jumpImg = $(this).attr("jumpImg");
					if(jumpImg!=nexImg){
						var after =$(".c-banner .banner ul li").eq(jumpImg);
						var befor =$(".c-banner .banner ul li").eq(nexImg);
						
						//将当前图片试用绝对定位,下一张图片试用相对定位
						$(".c-banner .banner ul img").eq(nexImg).css("position","absolute");
						$(".c-banner .banner ul img").eq(jumpImg).css("position","relative");
						
						after.css("display","block");
						after.stop().animate({"opacity":1},1000);
						befor.stop().animate({"opacity":0},1000,function(){
						befor.css("display","none");
						});
						nexImg=jumpImg;
					}
					$(this).css("background-color","black");
					time =setInterval(intervalImg,5000);
				});
			});*/
		},
		error:function(){
			alert("加载失败");
		}
	})
})
	//定时器返回值
	var time=null;
	//记录当前位子
	var nexImg = 0;
	//用于获取轮播图图片个数
	var imgLength =null; /* $(".c-banner .banner ul li").length; */
	//当时动态数据的时候使用,上面那个删除
	// var imgLength =0;
	//设置底部第一个按钮样式
	$(".c-banner .jumpBtn ul li[jumpImg=0]").css("background-color","black");

	//页面加载
	//轮播图
	function intervalImg(){
		if(nexImg<imgLength-1){
			nexImg++;
		}else{
			nexImg=0;
		}
		
		//将当前图片试用绝对定位,下一张图片试用相对定位
		$(".c-banner .banner ul img").eq(nexImg-1).css("position","absolute");
		$(".c-banner .banner ul img").eq(nexImg).css("position","relative");
		
		$(".c-banner .banner ul li").eq(nexImg).css("display","block");
		$(".c-banner .banner ul li").eq(nexImg).stop().animate({"opacity":1},1000);
		$(".c-banner .banner ul li").eq(nexImg-1).stop().animate({"opacity":0},1000,function(){
		$(".c-banner .banner ul li").eq(nexImg-1).css("display","none");
		});
		$(".c-banner .jumpBtn ul li").css("background-color","white");
		$(".c-banner .jumpBtn ul li[jumpImg="+nexImg+"]").css("background-color","black");
	}
	
var code="";
$(".game").on("click",".game_ct",function(){
	 $(".game_ct").css("background","url('../image/whiteborder.png') no-repeat");
	 $(".game_ct").css("background-size","100% 100%");
	 $(".game_ct").css("color","white");
	 $(this).css("background","url('../image/redborder.png') no-repeat");
	 $(this).css("background-size","100% 100%");
	 $(this).css("color","#F2CA95");
	 code=$(this).attr("data-code");
	 match(code);
	 twoMatch(code);
 })
 function match(code){
	$.ajax({
		url:"../nameController/getNameList",
		data:{
			"name":code
		},
		success:function(data){
			console.log(data);
			$('.match').html("");
			$.each(data,function(idex,item){
				$('.match').append("<div class='matchPic'><a href='../html/matchList.html?name_id="+item.id+"'><img src='"+item.matchPoster+"'></a></div>");
			})
			
		},
		error:function(){
			alert("加载失败");
		}
 })
}
 window.onload = function(){ 
    var current = 0;
    document.getElementById('arrow').onclick = function(){
        current = (current+180)%360;
        this.style.transform = 'rotate('+current+'deg)';
        $(".two").slideToggle(1000, function () {
        });
    }
};
function toMessage(){
	window.location.href="../html/Message.html"
}
function toMe(){
	window.location.href="../html/Me.html"
}

function mouseUp(){
	console.log(213123)
	intervalImg();
}

function mouseDown(e) {
	if(e.stopPropagation) e.stopPropagation();
	if(e.preventDefault) e.preventDefault();
}

$(function() {
	$.ajax({
		url:"../nameController/getGameList",
		data:{
			"pid":0
		},
		success:function(data){
			console.log(data);
			$('.game').html("");
			$.each(data,function(idex,item){
				$('.game').append("<div class='game_ct' data-code='"+item.id+"'>"+item.name+"</div>");
			})
			code=data[0].id;
			match(data[0].id);
			twoMatch(data[0].id);
		},
		error:function(){
			alert("加载失败");
		}
 })
})

function twoMatch(code) {
	$.ajax({
		url:"../matchController/getTwoMatch",
		data:{
			"code":code
		},
		success:function(data){
			console.log(data);
			$('.two').html("");
			$('#matchNub').html(data.length);
			$.each(data,function(idex,item){
				var h = new Date(item.start_time).getHours();
				var m = new Date(item.start_time).getMinutes();
				var startTime = h+":"+m
				var remark='';
				var sign_person=0;
				if(item.sign_person==null){
					sign_person=0
				}else{
					sign_person=item.sign_person
				}
				if(item.remark==null || item.remark=="" || item.remark=="undefined"){
					remark="无";
				}else{
					remark=item.remark
				}
				$('.two').append("<a href='../html/matchContent.html?id="+item.id+"'><div class='twoBox'><div class='gamePicBox'><img class='gamePic' src='"+item.matchListpic+"'></div><div class='gameContentBox'><div class='gameTitle'>"+item.name+"</div><div class='gameRank'><div class='area'>段位："+item.lowest_rank+"-"+item.highest_rank+"</div><div class='area'>"+item.region+"</div></div><div class='gameReward'>奖励："+remark+"</div></div><div class='gameSignUp'><div class='person'>已报<label class='endperson'>"+sign_person+"/"+item.max_person+"</label>人</div><div class='beginTime'>"+startTime+"开赛</div></div></div></a><hr/>");
			})
		},
		error:function(){
			alert("加载失败");
		}
 })
}



var rule;
$("#close").click(function(){
	$(".poster").css("display","none");
})
$(".kefu").click(function(){
	$(".posterBox img").attr("src",rule.card)
	$(".poster").css("display","flex");
})
$(function(){
	$.ajax({
		url:'../nameController/getRules',
		success:function(data){
			console.log(data);
			rule=data;
			if(New=="0"){
				$(".posterBox img").attr("src",data.newPerson)
				$(".poster").css("display","flex");
			}
			if(New=="1"){
				$(".posterBox img").attr("src",data.remark3)
				$(".poster").css("display","flex");
			}
		}
	})
})